// components/index_home/index_home.js
import tool from '../../modules/tool'
import store from '../../modules/store'



Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleShowFeedBack() {
      tool.store.setItem('showFeedBack')
    },
    handleClickMyHistory() {
      tool.handleShowActionSheet([{
          name: '全部历史巡查',
          callBack: () => {
            this.handleShowMyHsitoryTasksPage()
          }
        },
        {
          name: '待处理历史巡查',
          callBack() {
            tool.page.searchPatrol({
              patrolAccount: tool.store.getItem('userData').account,
              status: 1
            }, '待处理历史巡查')
          }
        },
        {
          name: '待评价历史巡查',
          callBack() {
            tool.page.searchPatrol({
              patrolAccount: tool.store.getItem('userData').account,
              status: 3
            })
          }
        },
        {
          name: '已完成历史巡查',
          callBack() {
            tool.page.searchPatrol({
              patrolAccount: tool.store.getItem('userData').account,
              status: 4
            }, '已完成历史巡查')
          }
        },
      ])
    },
    handleShowMyHsitoryTasksPage() {
      if (!tool.isLogined()) {
        tool.handleNotLogin()
        return
      }
      tool.postFrontStatus('点击历史巡查')
      tool.page.myHistoryTasks()
    },
    handleShowMyTasksPage() {
      if (!tool.isLogined()) {
        tool.handleNotLogin()
        return
      }
      tool.postFrontStatus('点击我的事务')
      tool.page.myTasks()
    },
    handleShowPatrolAddPage() {
      if (!tool.isLogined()) {
        tool.handleNotLogin()
        return
      }
      tool.postFrontStatus('点击新建巡查')
      tool.page.patrol.add()
    },
    handleAllowLongTap() {
      if (store.getItem('homeLongTap') === true) {
        store.removeItem('homeLongTap')
        tool.postFrontStatus('显示小程序开发者')
        tool.handleShowModel(`小程序开发者
聊城大学计算机学院2022级人工智能1班张天予
电话：17853441627`, false)
      }
    },
    handleTitleDataClick() {
      if (tool.isLogined()) {

      } else {
        tool.handleNotLogin()
      }
    }
  },

  attached() {
    this.setData({
      title: tool.store.getItem('userData') === undefined ? '点击登录，体验全部功能' : `${(() => {
        const now = new Date();
        const hour = now.getHours();

        if (hour >= 0 && hour < 6) {
          return "凌晨好";
        } else if (hour >= 6 && hour < 9) {
          return "早上好";
        } else if (hour >= 9 && hour < 12) {
          return "上午好";
        } else if (hour === 12) {
          return "中午好";
        } else if (hour > 12 && hour < 18) {
          return "下午好";
        } else if (hour >= 18 && hour < 20) {
          return "傍晚好";
        } else {
          return "晚上好";
        }
      })()}，${tool.store.getItem('userData').username}`,
      date: (() => {
        const now = new Date();
        const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
        const month = now.getMonth() + 1;
        const date = now.getDate();
        const day = weekdays[now.getDay()];
        return `${month}月${date}日 ${day}`;
      })()
    })
  }
})